﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Configuration;
using ECCIT.Extension.Weibo_v2.Common;
using OgilvyOne.UKNow.Mobile.Utilities;
using OgilvyOne.UKNow.DAL;
using OgilvyOne.UKNow.Mobile.Model.Events;
namespace OgilvyOne.UKNow.Mobile.APIs.Events
{
  public  class UpEvent:IHttpHandler
    {

        public bool IsReusable
        {
            get { throw new NotImplementedException(); }
        }

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var uid = context.Request.QueryString["uid"];
                var evenetid = context.Request.Params["eventid"];
                int iuid = 0;
                int eid = 0;
                if(int.TryParse(uid,out iuid))
                {

                }
                if(int.TryParse(evenetid,out eid))
                {

                }
                //int uid = int.Parse(context.Request.Params["uid"].ToString());
                //int eid = int.Parse(context.Request.Params["eventid"].ToString());
                if (iuid > 0 && eid > 0)
                {
                    var memmodel = new MemberBLL(2052).getMemberByID((int) iuid);
                    var emodel = new EventsBLL(2052).selEvent((int) eid);
                    if (memmodel != null && emodel != null)
                    {
                        upeve(iuid, eid, context);
                    }else
                    {
                        context.Response.Write(ResultUtility.ReturnResultJson("-501", "", "不存在该用户或活动"));
                    }

                }
                else
                {
                    context.Response.Write(ResultUtility.ReturnResultJson("-501", "", "参数错误"));
                }

            }
            catch (Exception ex)
            {
                context.Response.Write(ResultUtility.ReturnResultJson("-501","","用户对活动赞失败"+ex.Message));
                
            }
            


        }
        private void upeve(int uid,int eid ,HttpContext htc)
        {
            PraiseDAL pda = new PraiseDAL(2052);
            if (pda.ToPraise(uid, eid))
            {
                UserEvent ue = new UserEvent();
                ue.Uid = uid.ToString();
                ue.Eventid = eid.ToString();
                string s = JsonSerializationHelper.ObjectToJson(ue);
                htc.Response.Write(ResultUtility.ReturnResultJson("0", s, "用户对活动赞成功"));


            }
            else
            {
                htc.Response.Write(ResultUtility.ReturnResultJson("-500", "", "已赞过，不得重复"));
            }
            
        }
    }
}
